import items from './items.js';
import { ElCard } from 'element-plus';

const datas = [
	{ name: '张飞', sex: '男', age: 18, key: 0 },
	{ name: '吕布', sex: '男', age: 28, key: 1 },
	{ name: '赵云', sex: '男', age: 17, key: 2 },
];

let index = 1;
const initRow = () => {
	const idx = index++;
	const key = index + 2;
	return { name: `貂蝉${idx}`, sex: '女', age: 16, key };
}

export default function() {
	this.add({
		items,
		// 初始数据
		datas,
		is: $JiessTable,
		render(midder, { table }) {
			this.add({
				is: ElCard,
				$slots: {
					header: {
						is: $Between,
						left: '基础表单示例',
						right: {
							is: $ActionButtons,
							buttons: [{
								type: 'primary',
								text: '新增一行数据',
								onClick: () => {
									const py = midder.proxy;
									py.datas = [...py.datas, initRow()];
								}
							}, {
								text: '打印列表数据',
								onClick: () => {
									console.log(midder.proxy.datas)
								}
							}]
						}
					}
				},
				children: table
			})
		}
	})
}